package dp.test72;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/22 12:37
 */
public class Solution1 {

    public int minDistance(String word1, String word2) {
        if (word1.equals("")) return word2.length();
        if (word2.equals("")) return word1.length();
        int c1 = word1.length(), c2 = word2.length();
        int[][] dp = new int[c1 + 1][c2 + 1];
        for (int j = 1; j <= c2; j++) {
            dp[0][j] = j;
        }
        for (int i = 1; i <= c1; i++) {
            dp[i][0] = i;
        }
        for (int i = 1; i <= c1; i++) {
            for (int j = 1; j <= c2; j++) {
                if (word1.charAt(i - 1) == word2.charAt(j - 1)) {
                    dp[i][j] = dp[i - 1][j - 1];
                } else {
                    dp[i][j] = 1 + Math.min(dp[i - 1][j - 1], Math.min(dp[i - 1][j], dp[i][j - 1]));
                }
            }
        }
        return dp[c1][c2];
    }
}
